package com.CST.service.cb;

import com.CST.dto.cb.DateDTO;
import com.CST.entity.cb.CostDataInfo;
import com.CST.mapper.cst.cb.BaseSalaryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @BelongsProject: cbhs
 * @BelongsPackage: com.CST.service
 * @Author: lp
 * @CreateTime: 2023-03-13  16:40
 * @Description: TODO
 * @Version: 1.0
 */
@Component
public class ThreadService {

    @Autowired
    private BaseSalaryMapper baseSalaryMapper;

    @Autowired
    private IBaseSalaryService baseSalaryService;

    @Autowired
    private IAllocationCoefficientService allocationCoefficientService;

    @Autowired
    private IBaseCostService baseCostService;

    // 通知这个方法创建子线程运行
    @Async
    public void insertCostData(CostDataInfo costDataInfo){
        DateDTO dateDTO =new DateDTO();
        dateDTO.setYear(Integer.parseInt(costDataInfo.getYear()) );
        dateDTO.setMonth(Integer.parseInt(costDataInfo.getMonth()) );
        dateDTO.setYard("1");
        baseSalaryMapper.deleteByYearAndMonth(dateDTO.getYear(),dateDTO.getMonth());
        baseSalaryMapper.deleteDELByYearAndMonth(dateDTO.getYear(),dateDTO.getMonth());
        baseSalaryService.insertBaseSalary(dateDTO);
        allocationCoefficientService.insertCoefficient(dateDTO);
        baseCostService.insertBaseCost(costDataInfo);
        baseCostService.insertBaseCostDel(costDataInfo);
    }

}
